package com.atguigu.jucdemo.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

class MyThread implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println("你好啊!!");
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "完成任务";
    }
}

public class callableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask futureTask = new FutureTask(new MyThread());
        Thread t1 = new Thread(futureTask,"t1");



        t1.start();

        System.out.println(Thread.currentThread().getName()+"d");

        System.out.println(futureTask.get());

    }
}

